import { formatFileSize, isNullOrUndefined } from 'sks-plugin-el-erp/lib/core'
import Vue from 'vue'
import * as sksUtils from 'sks-plugin-el-erp/lib/core'

export function formatterFileSize(row, column) {
  let propName=column['property']
  let val=row[propName]
  console.log(`row.${propName}=${val}`)
  if(isNullOrUndefined(val)){
    return ''
  }

  return formatFileSize(val);
}

export function formatterTimeYmd(row,column){
  let propName=column['property']
  let val=row[propName]
  return sksUtils.parseTime(sksUtils.safeGet(row,propName),'{y}-{m}-{d}')
}

export function formatterTimeMdHm(row,column){
  let propName=column['property']
  let val=row[propName]
  return sksUtils.parseTime(sksUtils.safeGet(row,propName),'{m}-{d} {h}:{i}')
}

export function formatterTimeYmdHm(row,column){
  let propName=column['property']
  let val=row[propName]
  return sksUtils.parseTime(sksUtils.safeGet(row,propName),'{y}-{m}-{d} {h}:{i}')
}



//main中使用 require('utils/el-utils').install(Vue.prototype) 进行安装
export function install(root){
  root.formatterFileSize=formatterFileSize
  root.formatterTimeYmd=formatterTimeYmd
  root.formatterTimeMdHm=formatterTimeMdHm
  root.formatterTimeYmdHm=formatterTimeYmdHm
}
